package com.zs.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.StringUtil;
import com.zs.mapper.*;
import com.zs.pojo.*;
import com.zs.service.EmpService;
import com.zs.utils.PageResult;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/12/159:37
 */
@Service
public class EmpServiceImpl implements EmpService {

    @Resource
    private TEmpMapper tEmpMapper;

    @Resource
    private TDempMapper tDempMapper;

    @Resource
    private TZhiweiMapper tZhiweiMapper;

    @Resource
    private TQingjiaMapper tQingjiaMapper;

    @Resource
    private TXzmxMapper tXzmxMapper;

    @Override
    public PageResult<TEmp> pagelist(TEmp tEmp, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        TEmpExample example = new TEmpExample();
        TEmpExample.Criteria criteria = example.createCriteria();
        if(tEmp !=null){
            if(StringUtil.isNotEmpty(tEmp.getName())){
                criteria.andNameLike("%"+tEmp.getName()+"%");
            }
            if(tEmp.getPhone() != null && tEmp.getPhone() != 0){
                criteria.andPhoneEqualTo(tEmp.getPhone());
            }
            if(StringUtil.isNotEmpty(tEmp.getSex())){
                criteria.andSexEqualTo(tEmp.getSex());
            }
            if(tEmp.getDepid() != null && tEmp.getDepid() != 0){
                criteria.andDepidEqualTo(tEmp.getDepid());
            }
            if(tEmp.getZhiweiid() != null && tEmp.getZhiweiid() != 0){
                criteria.andZhiweiidEqualTo(tEmp.getZhiweiid());
            }
        }
        Page<TEmp> tEmps = (Page<TEmp>) tEmpMapper.selectByExample(example);
        return new PageResult<>(tEmps.getTotal(),tEmps.getResult());
    }

    @Override
    public List<TDemp> getDePts() {
        return tDempMapper.selectByExample(null);
    }

    @Override
    public List<TZhiwei> getZhiweis() {
        return tZhiweiMapper.selectByExample(null);
    }

    @Override
    public void saveQj(TQingjia tQingjia) {
        tQingjiaMapper.insert(tQingjia);
    }

    @Override
    public Map<String,Object> xzmx(Integer empid) {
        TXzmxExample example = new TXzmxExample();
        TXzmxExample.Criteria criteria = example.createCriteria();
        criteria.andEmpidEqualTo(empid);
        TXzmx tXzmx = tXzmxMapper.selectByExample(example).get(0);

        TQingjiaExample tQingjiaExample = new TQingjiaExample();
        TQingjiaExample.Criteria criteria1 = tQingjiaExample.createCriteria();
        criteria1.andEmpidEqualTo(empid);
        List<TQingjia> tQingjias = tQingjiaMapper.selectByExample(tQingjiaExample);
        HashMap<String, Object> map = new HashMap<>();
        map.put("tXzmx",tXzmx);
        map.put("tQingjias",tQingjias);
        return  map;
    }
}
